﻿using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;

public partial class LoginPasswordList : System.Web.UI.Page
{
    Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Convert.ToBoolean(Session["sAdministrator"].ToString()) == false)
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
            string sqlQuery = "OPEN SYMMETRIC KEY PrivateDataKey DECRYPTION BY CERTIFICATE PrivateDataCertificate SELECT [Login],[Description],CONVERT(NVARCHAR(500),DECRYPTBYKEY(EncryptedPassword)) AS UnEncryptedPassword FROM LoginPassword CLOSE SYMMETRIC KEY PrivateDataKey;";

            DataSet ds = db.ExecuteDataSet(CommandType.Text, sqlQuery);

            this.gv.DataSource = ds;
            this.gv.DataBind();
        }
        
    }
}
